{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">申请帮扶列表</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <div class="temTable layui-fluid"><div class="temTable-member-list layui-fluid">
                账号：
                <div class="layui-inline">
                    <input type="text" class="layui-input" id="mobile" name=mobile" placeholder="输入账号,手机号">
                </div>
                申请时间：
                <div class="layui-inline">
                    <input type="text" class="layui-input" id="addtime" name="addtime" >
                </div>
                状态:
                <div class="layui-inline">
                    <select class="layui-form-select" id="status" name="status">
                        <option value="">请选择</option>
                        <option value="-1">未帮扶</option>
                        <option value="-2">未审核</option>
                        <option value="1">待帮扶</option>
                        <option value="2">已帮扶</option>
                        <option value="3">已完成</option>
                        <option value="4">已归档</option>
                    </select>
                </div>
                <button class="layui-btn search" data-type="reload">搜索</button>
                <button class="layui-btn layui-btn-danger" data-type="export">导出</button>
            </div>
            </div>
            <table class="layui-hide" id="table" lay-filter="table"></table>
            <!--<script type="text/html" id="toolbarDemo">-->
            <!--<div class="layui-btn-container">-->
            <!--<a class="layui-btn layui-btn-sm" href="{:url('admin/member/add')}">添加会员</a>-->
            <!--</div>-->
            <!--</script>-->
            <script type="text/html" id="barTool">
                <a class="layui-btn layui-btn-xs" lay-event="info">详情</a>
                {{#  if(d.status == 0){ }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="sendHelp">指派</a>
                {{#  } else if(d.status == -1) { }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="return">删除</a>
                {{#  } else if(d.status == 2) { }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="pass">通过</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="fail">拒绝</a>
                {{#  } else if(d.status == 3) { }}
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="finish">归档</a>
                {{#  } }}
            </script>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['table','laydate','form'], function() {
        var table = layui.table,
            $ = layui.$
            ,admin = layui.admin
            ,view = layui.view
            ,laydate = layui.laydate;

        //日期时间范围
        laydate.render({
            elem: '#addtime'
            ,type: 'datetime'
            ,range: true
        });

        table.render({
            elem: '#table',
            toolbar: '#toolbarDemo',
            url: '{:url("admin/applyhelp/indexUrgent")}',
            cols: [
                [
                    { field: 'id', width: 80, title: 'ID',fixed:true},
                    { field: 'level', width: 80, title: '等级',fixed:true},
                    { field: 'username', width: 120, title: '申请人账号',fixed:true},
                    { field: 'is_dang', width: 90, title: '是否党员'},
                    { field: 'status_name', width: 120, title: '帮扶状态'},
                    { field: 'eName', width: 120, title: '志願者'},
                    { field: 'hName', width: 120, title: '镇街/村居'},
                    { field: 'type', width: 200, title: '类型'},
                    { field: 'name', width: 120,title: '姓名'},
                    { field: 'nation', width: 80, title: '民族'},
                    { field: 'sex',width: 80, title: '性别' },
                    { field: 'born_date',width: 200, title: '出生年月日' },
                    { field: 'mobile', width: 120,title: '手机号' },
                    { field: 'danwei', width: 120,title: '所属单位' },
                    { field: 'zhibu', width: 120,title: '所属支部' },
                    { field: 'work_address', width: 200,title: '工作单位地址' },
                    { field: 'work_address_info', width: 200,title: '工作单位详细地址' },
                    { field: 'rudang_date', width: 120,title: '入党时间' },
                    { field: 'msg', width: 120,title: '基本情况' },
                    { field: 'msg_info', width: 200,title: '基本情况详情' },
                    { field: 'id_img_up', title: '图片',width: 130 , align: 'center',templet:'<div><img style="height:100px;width:100px;" src="{{d.id_img_up}}"></div>'},
                    { field: 'id_img_down', title: '图片',width: 130 , align: 'center',templet:'<div><img style="height:100px;width:100px;" src="{{d.id_img_down}}"></div>'},
                    { field: 'create_time', width: 120,title: '申请时间' },
                    { field: 'pass_time', width: 120,title: '审核通过时间' },
                    { field: 'finish_time', width: 120,title: '完成时间' },
                    { fixed: 'right', width: 160, title: '操作', toolbar: '#barTool' }
                ]
            ],
            id: 'testReload',
            page: {}
        });

        //监听行工具事件
        table.on('tool(table)', function(obj) {
            var data = obj.data;
            if (obj.event === 'info') {
                window.open('{:url("admin/applyhelp/info")}' + "?id=" + data.id, '_self')
            }else if (obj.event === 'pass') {
                window.open('{:url("admin/applyhelp/makeSure")}' + "?id=" + data.id, '_self')
            }else if(obj.event === 'finish'){
                layer.confirm('确定归档此条申请？', { icon: 3, title: '提示' }, function(index) {
                    layer.close(index);
                    $.post('{:url("admin/applyhelp/finish")}', { 'id': data.id }, function(data) {
                        if (data.code == 1) {
                            if (data.url) {
                                layer.msg(data.msg + ' 页面即将自动跳转~');
                            } else {
                                layer.msg(data.msg);
                            }
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                } else {
                                    location.reload();
                                }
                            }, 1500);
                        } else {
                            layer.msg(data.msg);
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                }
                            }, 1500);
                        }

                    });
                });
            }else if(obj.event === 'sendHelp'){
                layer.open({
                    type: 2,
                    title: '指派帮助人',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['50%', '80%'],
                    content: '/admin/applyHelp/helpMember?id='+data.id    //直接显示某个页面的内容
                });
            }else if(obj.event === 'fail'){
                layer.open({
                    type: 2,
                    title: '拒绝申请',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['50%', '80%'],
                    content: '/admin/applyHelp/fail?id='+data.id    //直接显示某个页面的内容
                });
            }
        });


        var $ = layui.$, active = {
            reload: function () {
                var mobile = $("#mobile").val();
                var time = $("#addtime").val();
                var status = $("#status").val();
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
//                        key: {
                        mobile: mobile,
                        status: status,
                        time: time
//                        }
                    }
                });
            },
            export:function() {

                var mobile = $("#mobile").val();
                var time = $("#addtime").val();
                var status = $("#status").val();

                window.open('{:url("admin/applyhelp/export")}' + "?mobile=" +mobile + "&time="+time + "&status="+status+"&type=1", '_self');
            }
        };
        $('.temTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });
</script>
{/block}